﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LPY.LeHealth.Model;
using LPY.LeHealth.DTO;
using LPY.LeHealth.Service;

namespace LPY.LeHealth.WebSite.Controllers
{
    public class QuestionsController : Controller
    {
        private QuestionService question;
        public QuestionsController()
        {
            question = new QuestionService();
        }
        //
        // GET: /Questions/
        public ActionResult Index()
        {
            return View();
        }
         //<summary>
         //已解答显示返回Json
         //</summary>
         //<returns></returns>
        public JsonResult yesquestions()
        {
            int uid = Convert.ToInt32(Session["useid"]);
            string state = "已解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetQuestion(uid, state);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }       
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        //<summary>
        //未解答显示返回Json
        //</summary>
        //<returns></returns>
        public JsonResult noquestions()
        {
            string state = "未解答";
            int uid = Convert.ToInt32(Session["useid"]);
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetQuestion(uid, state);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        //根据体检分类id和体检项id显示前5条
        //</summary>
        //<param name="id"></param>
        //<param name="eid"></param>
        //<returns></returns>
        public JsonResult GetQuestionshow(int eid,int id)
        {
            Session["eid"] = eid;
            Session["id"] = id;
            string state = "未解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetQuestionshow(eid,id);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        
             /// <summary>
        //根据体检分类id和体检项id显示
        //</summary>
        //<param name="id"></param>
        //<param name="eid"></param>
        //<returns></returns>
        public JsonResult GetQuestionshowall()
        {
             int eid=Convert.ToInt32(Session["eid"]);
             int id=Convert.ToInt32(Session["id"]);
            string state = "未解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetQuestionshow(eid,id);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 根据体检分类Id查找问答信息前5条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public JsonResult GetquestionId(int Id)
        {
            string state = "未解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetQuestionId(Id);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 获取Id
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public JsonResult ToId(int Id)
        {
            Session["ID"] = Id;

            return Json(Session["ID"], JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 根据Id查询数据表数量
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public int GetCount(int Id)
        {
            return question.GetCount(Id);
        }
        /// <summary>
        /// 根据体检分类Id查找问答信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public JsonResult GetquestionIdall()
        {
            int Id = Convert.ToInt32(Session["ID"]);
            string state = "未解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetQuestionIdall(Id);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);

        }
        [HttpGet]
        /// <summary>
        /// 获取显示未解答信息前几条
        /// </summary>
        /// <returns></returns>
        public JsonResult GetComent(string Qstate)
        {
            Session["Qstate"] = "";
            Session["Qstate"] = Qstate;
            int uid =Convert.ToInt32(Session["useid"]);
            string state = "未解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetNoConment(uid,Qstate);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }
         /// <summary>
        /// 获取显示未解答信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetNoComentall()
        {
            int uid =Convert.ToInt32(Session["useid"]);
            string state = "未解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetNoConmentall(uid, Session["Qstate"].ToString());
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 搜所
        /// </summary>
        /// <param name="Content"></param>
        /// <returns></returns>
        public JsonResult GetquestionSerch(string Content)
        {
            //int eid =Convert.ToInt32(Session["eid"]);
            string state = "未解答";
            Common.JsonMessage jm = new Common.JsonMessage();
            List<questions> list = question.GetQuesionSeach(Content);
            if (list.Count > 0)
            {
                jm.Code = 1;
                jm.Msg = "获取数据成功";
                jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }
            return Json(list, JsonRequestBehavior.AllowGet);

              
        }
        [HttpGet]
        /// <summary>
        /// 获取解决问题数量
        /// </summary>
        /// <returns></returns>
        public JsonResult GetQuesionCount()
        {
            return Json(question.GetQuesionCount(),JsonRequestBehavior.AllowGet);
        }



	}
}